<?php
//include($_SERVER['DOCUMENT_ROOT'] . '/june/classes/avatar_class.php');
include_once('../includes/initialize.php');



// DEFINE TO CLASSES
$avatarClass = new AvatarClass;


// GET THE POST VARIABLE
$postId = isset($_POST['id'])?$_POST['id']:false; 


// MAKE SURE FILE UPLOAD
   $files    = isset($_FILES["fileUploadPic"]) ? $_FILES["fileUploadPic"] : $_FILES["ieFileUploadPic"];
   
/*
   echo"<pre>";
   print_r($files);
   echo"</pre>"; // */
 
   
      
// GET NECESSARY FILE INFO   
   $fileName = $files["name"];
   $fileSize = $files["size"];
   $tmpName  = $files["tmp_name"];
 
 
// CHECK FOR VALID FILE EXTENSIONS	 
   $validExt 	= array('.jpg', '.jpeg', '.gif', '.png', '.bmp');
   $getExt   	= strtolower(strrchr($fileName, '.'));
   $getFileSize = round($fileSize / 1024, 1);
   $maxSize 	= '10000'; // 1 MB
     
// CHECK FOR FILE     
   if( !empty( $fileName ) )
   {			 
		if(in_array( $getExt, $validExt))
		{
			if( $getFileSize < $maxSize )
			{
								   
				// NOW LETS TRY TO SAVE IMAGE
				   
						 // CREATE NEW FILE NAME
						    $targetFileName = $postId.".jpg";
						
						 // SET TARGET DESTINATION
							$targetAvatar = DOC_ROOT . "media/images/gallery/" .$targetFileName;
							
						 // MOVE THE IMAGE AND SAVE IT
							$avatarClass->uploadAvatar($files, $targetAvatar, $postId, 570);			
							
						 // DISPLAY IMAGE
						echo "<img src='". WEB_ROOT ."media/images/gallery/".$targetFileName."' alt='".$targetFileName."' class='avatar'  width='100%' >";
				}
			else
			{
				echo 'Filesize is large ('.$getfileSize.' KB) that should be less then 1 MB'; 
			}
		}
		else{
			echo 'File not Supported!'; 
		}
   }   
   //*/
   //print_r($_FILES);
   ?>